package com.zc.operator.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zc.operator.domain.ChargeStationDeviceExtend;
import com.zc.operator.service.IChargeStationDeviceExtendService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 场站设备关联Controller
 * 
 * @author glb
 * @date 2024-02-03
 */
@RestController
@RequestMapping("/operator/extend")
public class ChargeStationDeviceExtendController extends BaseController
{
    @Autowired
    private IChargeStationDeviceExtendService chargeStationDeviceExtendService;

    /**
     * 查询场站设备关联列表
     */
    @PreAuthorize("@ss.hasPermi('operator:extend:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChargeStationDeviceExtend chargeStationDeviceExtend)
    {
        startPage();
        List<ChargeStationDeviceExtend> list = chargeStationDeviceExtendService.selectChargeStationDeviceExtendList(chargeStationDeviceExtend);
        return getDataTable(list);
    }

    /**
     * 导出场站设备关联列表
     */
    @PreAuthorize("@ss.hasPermi('operator:extend:export')")
    @Log(title = "场站设备关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChargeStationDeviceExtend chargeStationDeviceExtend)
    {
        List<ChargeStationDeviceExtend> list = chargeStationDeviceExtendService.selectChargeStationDeviceExtendList(chargeStationDeviceExtend);
        ExcelUtil<ChargeStationDeviceExtend> util = new ExcelUtil<>(ChargeStationDeviceExtend.class);
        util.exportExcel(response, list, "场站设备关联数据");
    }

    /**
     * 获取场站设备关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('operator:extend:query')")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") String deviceId)
    {
        return AjaxResult.success(chargeStationDeviceExtendService.selectChargeStationDeviceExtendByDeviceId(deviceId));
    }

    /**
     * 新增场站设备关联
     */
    @PreAuthorize("@ss.hasPermi('operator:extend:add')")
    @Log(title = "场站设备关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargeStationDeviceExtend chargeStationDeviceExtend)
    {
        return toAjax(chargeStationDeviceExtendService.insertChargeStationDeviceExtend(chargeStationDeviceExtend));
    }

    /**
     * 修改场站设备关联
     */
    @PreAuthorize("@ss.hasPermi('operator:extend:edit')")
    @Log(title = "场站设备关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargeStationDeviceExtend chargeStationDeviceExtend)
    {
        return toAjax(chargeStationDeviceExtendService.updateChargeStationDeviceExtend(chargeStationDeviceExtend));
    }

    /**
     * 删除场站设备关联
     */
    @PreAuthorize("@ss.hasPermi('operator:extend:remove')")
    @Log(title = "场站设备关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable String[] deviceIds)
    {
        return toAjax(chargeStationDeviceExtendService.deleteChargeStationDeviceExtendByDeviceIds(deviceIds));
    }
}
